package com.lineage.server.model;

import com.lineage.config.ConfigAlt;
import com.lineage.config.ConfigDarkElfSkill;
import com.lineage.config.ConfigElfSkill;
import com.lineage.config.ConfigGuaji;
import com.lineage.config.ConfigIllusionstSkill;
import com.lineage.config.ConfigKnightSkill;
import com.lineage.config.ConfigOther;
import com.lineage.config.ConfigWizardSkill;
import com.lineage.config.Config_Pc_Damage;
import com.lineage.server.datatables.NpcTable;
import com.lineage.server.datatables.SkillsTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.Instance.L1SummonInstance;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1ItemSpecialAttributeChar;
import com.lineage.server.templates.L1Npc;
import com.lineage.server.templates.L1Skills;
import com.lineage.server.timecontroller.server.ServerWarExecutor;
import com.lineage.server.utils.L1SpawnUtil;
import com.lineage.server.utils.Random;
import com.lineage.server.utils.RandomArrayList;

import static com.lineage.server.model.skill.L1SkillId.EXTRA_HEAL;
import static com.lineage.server.model.skill.L1SkillId.FULL_HEAL;
import static com.lineage.server.model.skill.L1SkillId.GREATER_HEAL;
import static com.lineage.server.model.skill.L1SkillId.HEAL;
import static com.lineage.server.model.skill.L1SkillId.NATURES_BLESSING;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1MagicPc extends L1MagicMode {
  private static final Log _log = LogFactory.getLog(L1MagicPc.class);
  
  protected L1ItemInstance _weapon;
  
  L1ItemSpecialAttributeChar item_attr_char = null;
  
  public L1MagicPc(L1PcInstance attacker, L1Character target) {
    if (attacker == null)
      return; 
    this._pc = attacker;
    if (target instanceof L1PcInstance) {
      this._calcType = 1;
      this._targetPc = (L1PcInstance)target;
    } else {
      this._calcType = 2;
      this._targetNpc = (L1NpcInstance)target;
    } 
  }
  
  private static boolean isInWarAreaAndWarTime(L1PcInstance pc) {
    int castleId = L1CastleLocation.getCastleIdByArea((L1Character)pc);
    return (castleId != 0 && ServerWarExecutor.get().isNowWar(castleId));
  }
  
  private int getMagicLevel() {
    return this._pc.getMagicLevel();
  }
  
  private int getMagicBonus() {
    return this._pc.getMagicBonus();
  }
  
  private int getLawful() {
    return this._pc.getLawful();
  }
  
  public boolean calcProbabilityMagic(int skillId) {
    boolean castle_area;
    int probability = 0;
    boolean isSuccess = false;
    switch (this._calcType) {
      case 1:
        if (skillId == 44 && this._pc != null && this._targetPc != null) {
          if (this._pc.getId() == this._targetPc.getId())
            return true; 
          if (this._pc.getClanid() > 0 && this._pc.getClanid() == this._targetPc.getClanid())
            return true; 
        } 
        if (skillId == 67) {
          if (this._pc.getId() == this._targetPc.getId())
            return true; 
          if (this._pc.getClanid() > 0 && this._pc.getClanid() == this._targetPc.getClanid())
            return true; 
        } 
        if (ConfigGuaji.Guaji_save && this._targetPc.isActived() && 
          this._targetPc.getLevel() <= ConfigGuaji.Guaji_level)
          return false; 
        if (this._targetPc == this._pc)
          return false; 
        castle_area = L1CastleLocation.checkInAllWarArea(this._targetPc.getX(), this._targetPc.getY(), 
            this._targetPc.getMapId());
        if (this._targetPc.getnewcharpra())
          return false; 
        if (this._pc.getnewcharpra())
          return false; 
        if (!checkZone(skillId))
          return false; 
        if (this._targetPc.hasSkillEffect(50) && skillId != 44)
          return false; 
        if (this._targetPc.hasSkillEffect(157) && skillId != 44)
          return false; 
        if (calcEvasion())
          return false; 
        break;
      case 2:
        if (this._targetNpc != null) {
          if (this._targetNpc instanceof com.lineage.server.model.Instance.L1DeInstance && !checkZoneDE(skillId))
            return false; 
          int gfxid = this._targetNpc.getNpcTemplate().get_gfxid();
          switch (gfxid) {
            case 2412:
              if (!this._pc.getInventory().checkEquipped(20046))
                return false; 
              break;
          } 
          int npcId = this._targetNpc.getNpcTemplate().get_npcId();
          Integer tgskill = L1AttackList.SKNPC.get(Integer.valueOf(npcId));
          if (tgskill != null && !this._pc.hasSkillEffect(tgskill.intValue()))
            return false; 
          Integer tgpoly = L1AttackList.PLNPC.get(Integer.valueOf(npcId));
          if (tgpoly != null && tgpoly.equals(Integer.valueOf(this._pc.getTempCharGfx())))
            return false; 
          boolean dgskill = L1AttackList.DNNPC.containsKey(Integer.valueOf(npcId));
          if (dgskill) {
            Integer[] dgskillids = L1AttackList.DNNPC.get(Integer.valueOf(npcId));
            Integer[] array;
            int length = (array = dgskillids).length;
            int i = 0;
            while (i < length) {
              Integer dgskillid = array[i];
              if (dgskillid.equals(Integer.valueOf(skillId)))
                return false; 
              i++;
            } 
          } 
        } 
        if (skillId == 44)
          return true; 
        if (skillId == 67 && this._targetNpc.getLevel() >= 50)
          return false; 
        if (this._targetNpc.hasSkillEffect(50) && skillId != 27 && skillId != 44)
          return false; 
        if (this._targetNpc.hasSkillEffect(157) && skillId != 27 && skillId != 44)
          return false; 
        break;
    } 
    probability = calcProbability(skillId);
    if ((this._calcType == 1 || this._calcType == 2) && this._pc.isWizard() && 
      this._pc.getlogpcpower_SkillFor3() != 0)
      probability += this._pc.getlogpcpower_SkillFor3(); 
    if (skillId == 208 && this._pc.getlogpcpower_SkillFor3() != 0)
      probability += this._pc.getlogpcpower_SkillFor3(); 
    int rnd = L1MagicMode._random.nextInt(100) + 1;
    if (probability >= rnd) {
      isSuccess = true;
      if (this._pc.isGm())
        this._pc.sendPackets((ServerBasePacket)new S_SystemMessage("玩家发动:" + probability + "大于系统发动值" + rnd + "触发")); 
    } else {
      isSuccess = false;
      if (this._pc.isGm())
        this._pc.sendPackets((ServerBasePacket)new S_SystemMessage("玩家发动:" + probability + "小于系统发动值" + rnd + "失败")); 
    } 
    if (!ConfigAlt.ALT_ATKMSG)
      return isSuccess; 
    switch (this._calcType) {
      case 1:
        if (!this._pc.isGm() && !this._targetPc.isGm())
          return isSuccess; 
        break;
      case 2:
        if (!this._pc.isGm())
          return isSuccess; 
        break;
    } 
    switch (this._calcType) {
      case 1:
        if (this._pc.isGm()) {
          StringBuilder atkMsg = new StringBuilder();
          atkMsg.append("对PC送出技能: ");
          atkMsg.append(String.valueOf(String.valueOf(this._pc.getName())) + ">");
          atkMsg.append(String.valueOf(String.valueOf(this._targetPc.getName())) + " ");
          atkMsg.append(isSuccess ? "成功" : "失败");
          atkMsg.append(" 成功机率:" + probability + "%");
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, atkMsg.toString()));
        } 
        if (this._targetPc.isGm()) {
          StringBuilder atkMsg = new StringBuilder();
          atkMsg.append("受到PC技能: ");
          atkMsg.append(String.valueOf(String.valueOf(this._pc.getName())) + ">");
          atkMsg.append(String.valueOf(String.valueOf(this._targetPc.getName())) + " ");
          atkMsg.append(isSuccess ? "成功" : "失败");
          atkMsg.append(" 成功机率:" + probability + "%");
          this._targetPc.sendPackets((ServerBasePacket)new S_ServerMessage(166, atkMsg.toString()));
        } 
        break;
      case 2:
        if (this._pc.isGm()) {
          StringBuilder atkMsg = new StringBuilder();
          atkMsg.append("对NPC送出技能: ");
          atkMsg.append(String.valueOf(String.valueOf(this._pc.getName())) + ">");
          atkMsg.append(String.valueOf(String.valueOf(this._targetNpc.getName())) + " ");
          atkMsg.append(isSuccess ? "成功" : "失败");
          atkMsg.append(" 成功机率:" + probability + "%");
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, atkMsg.toString()));
        } 
        break;
    } 
    return isSuccess;
  }
  
  private boolean checkZone(int skillId) {
    if (this._pc != null && this._targetPc != null && (this._pc.isSafetyZone() || this._targetPc.isSafetyZone())) {
      Boolean isBoolean = L1AttackList.NZONE.get(Integer.valueOf(skillId));
      if (isBoolean != null) {
        this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("在安全区域无法使用此技能。"));
        return false;
      } 
    } 
    return true;
  }
  
  private boolean checkZoneDE(int skillId) {
    if (this._pc != null && this._targetNpc != null && (
      this._pc.isSafetyZone() || this._targetNpc.isSafetyZone())) {
      Boolean isBoolean = L1AttackList.NZONE.get(Integer.valueOf(skillId));
      if (isBoolean != null) {
        this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("在安全区域无法使用此技能。"));
        return false;
      } 
    } 
    return true;
  }
  
  private int calcProbability(int skillId) {
    int dice2, diceCount2, i;
    L1Skills l1skills = SkillsTable.get().getTemplate(skillId);
    int attackLevel = this._pc.getLevel();
    int defenseLevel = 0;
    int probability = 0;
    int defenseMr = 0;
    switch (this._calcType) {
      case 1:
        defenseLevel = this._targetPc.getLevel();
        defenseMr = this._targetPc.getMr();
        break;
      case 2:
        defenseLevel = this._targetNpc.getLevel();
        if (skillId == 145 && this._targetNpc instanceof L1SummonInstance) {
          L1SummonInstance summon = (L1SummonInstance)this._targetNpc;
          defenseLevel = summon.getMaster().getLevel();
        } 
        break;
    } 
    Integer magichit = L1AttackList.INTH.get(Integer.valueOf(this._pc.getInt()));
    if (magichit == null)
      magichit = Integer.valueOf(0); 
    if (this._calcType == 1 && (
      skillId == 27 || skillId == 29 || skillId == 33 || skillId == 47 || skillId == 50 || skillId == 59 || 
      skillId == 64 || skillId == 66 || skillId == 71 || skillId == 152 || skillId == 167 || 
      skillId == 153 || skillId == 157 || skillId == 161 || skillId == 173 || skillId == 174 || 
      skillId == 39 || skillId == 103 || skillId == 183 || skillId == 188 || skillId == 193 || 
      skillId == 202 || skillId == 212 || skillId == 217 || skillId == 11 || skillId == 20 || 
      skillId == 40 || skillId == 76) && 
      !isInWarAreaAndWarTime(this._pc, this._targetPc) && !this._targetPc.isPinkName() && 
      !this._targetPc.isCombatZone())
      L1PinkName.runPinkNameTimer(this._pc); 
    switch (skillId) {
      case 18:
        probability = l1skills.getProbabilityValue();
        if (l1skills.gettype1() != 0 && attackLevel > defenseLevel)
          probability = l1skills.gettype1(); 
        if (l1skills.gettype2() != 0 && attackLevel == defenseLevel)
          probability = l1skills.gettype2(); 
        if (l1skills.gettype3() != 0 && attackLevel < defenseLevel)
          probability = l1skills.gettype3(); 
        if (l1skills.gettype4() != 0)
          probability += l1skills.gettype4(); 
        if (l1skills.gettype5() != 0)
          probability += l1skills.gettype5() * (attackLevel - defenseLevel) / 10; 
        if (l1skills.gettype6() != 0)
          probability += l1skills.gettype6() * this._pc.getInt() / 10; 
        if (l1skills.gettype7() != 0)
          probability += l1skills.gettype7() + (attackLevel - defenseLevel) * 5; 
        if (l1skills.gettype8() != 0)
          probability += l1skills.gettype8() + (attackLevel - defenseLevel) * 2; 
        if (l1skills.gettype9() != 0)
          probability += l1skills.gettype9() + attackLevel - defenseLevel; 
        if (l1skills.gettype10() != 0 && this._pc.getInt() >= l1skills.gettype10())
          probability += 3; 
        if (l1skills.gettype11() != 0)
          probability += l1skills.gettype11() * (attackLevel - defenseLevel); 
        if (l1skills.gettype12() != 0)
          probability = (int)(probability + 
            l1skills.gettype12() + (this._pc.getMr() - l1skills.gettype12()) * 0.02D); 
        if (l1skills.gettype13() != 0)
          probability = (int)(probability + 
            l1skills.gettype13() + (this._pc.getMr() - l1skills.gettype13()) * 0.04D); 
        if (this._calcType == 1 && l1skills.gettype14() != 0 && this._targetPc.getMr() >= l1skills.gettype14())
          probability -= l1skills.gettype14() / 7; 
        if (this._calcType == 1 && l1skills.gettype15() != 0 && this._targetPc.getMr() >= l1skills.gettype15())
          probability -= l1skills.gettype15() / 9; 
        if (this._calcType == 1 && l1skills.gettype16() != 0 && this._targetPc.getMr() >= l1skills.gettype16())
          probability -= l1skills.gettype16() / 13; 
        if (this._calcType == 1 && l1skills.gettype17() != 0 && this._targetPc.getMr() >= l1skills.gettype17())
          probability -= l1skills.gettype17() / 15; 
        if (this._calcType == 1 && l1skills.gettype18() != 0 && this._targetPc.getMr() >= l1skills.gettype18())
          probability -= l1skills.gettype18() / 20; 
        if (this._calcType == 1 && l1skills.gettype19() != 0 && this._targetPc.getMr() >= l1skills.gettype19())
          probability -= 15; 
        if (l1skills.gettype20() != 0 && attackLevel - defenseLevel > l1skills.gettype20())
          probability = 70; 
        if (l1skills.gettype21() != 0 && probability >= l1skills.gettype21())
          probability = l1skills.gettype21(); 
        if (this._calcType == 1 && l1skills.gettype22() != 0 && this._targetPc.getMr() >= l1skills.gettype22())
          probability = 5; 
        if (this._calcType == 1 && l1skills.gettype24() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype24()) / 7; 
        if (this._calcType == 1 && l1skills.gettype25() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype25()) / 9; 
        if (this._calcType == 1 && l1skills.gettype26() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype26()) / 13; 
        if (this._calcType == 1 && l1skills.gettype27() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype27()) / 15; 
        if (this._calcType == 1 && l1skills.gettype28() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype28()) / 20; 
        if (this._pc.isWizard() && probability > 70) {
          probability = 70;
          break;
        } 
        if (!this._pc.isElf())
          break; 
        if (probability > 70) {
          probability = 55;
          break;
        } 
        probability /= 2;
        break;
      case 91:
        probability = l1skills.getProbabilityValue();
        if (l1skills.gettype1() != 0 && attackLevel > defenseLevel)
          probability = l1skills.gettype1(); 
        if (l1skills.gettype2() != 0 && attackLevel == defenseLevel)
          probability = l1skills.gettype2(); 
        if (l1skills.gettype3() != 0 && attackLevel < defenseLevel)
          probability = l1skills.gettype3(); 
        if (l1skills.gettype4() != 0)
          probability += l1skills.gettype4(); 
        if (l1skills.gettype5() != 0)
          probability += l1skills.gettype5() * (attackLevel - defenseLevel) / 10; 
        if (l1skills.gettype6() != 0)
          probability += l1skills.gettype6() * this._pc.getInt() / 10; 
        if (l1skills.gettype7() != 0)
          probability += l1skills.gettype7() + (attackLevel - defenseLevel) * 5; 
        if (l1skills.gettype8() != 0)
          probability += l1skills.gettype8() + (attackLevel - defenseLevel) * 2; 
        if (l1skills.gettype9() != 0)
          probability += l1skills.gettype9() + attackLevel - defenseLevel; 
        if (l1skills.gettype10() != 0 && this._pc.getInt() >= l1skills.gettype10())
          probability += 3; 
        if (l1skills.gettype11() != 0)
          probability += l1skills.gettype11() * (attackLevel - defenseLevel); 
        if (l1skills.gettype12() != 0)
          probability = (int)(probability + 
            l1skills.gettype12() + (this._pc.getMr() - l1skills.gettype12()) * 0.02D); 
        if (l1skills.gettype13() != 0)
          probability = (int)(probability + 
            l1skills.gettype13() + (this._pc.getMr() - l1skills.gettype13()) * 0.04D); 
        if (this._calcType == 1 && l1skills.gettype14() != 0 && this._targetPc.getMr() >= l1skills.gettype14())
          probability -= l1skills.gettype14() / 7; 
        if (this._calcType == 1 && l1skills.gettype15() != 0 && this._targetPc.getMr() >= l1skills.gettype15())
          probability -= l1skills.gettype15() / 9; 
        if (this._calcType == 1 && l1skills.gettype16() != 0 && this._targetPc.getMr() >= l1skills.gettype16())
          probability -= l1skills.gettype16() / 13; 
        if (this._calcType == 1 && l1skills.gettype17() != 0 && this._targetPc.getMr() >= l1skills.gettype17())
          probability -= l1skills.gettype17() / 15; 
        if (this._calcType == 1 && l1skills.gettype18() != 0 && this._targetPc.getMr() >= l1skills.gettype18())
          probability -= l1skills.gettype18() / 20; 
        if (this._calcType == 1 && l1skills.gettype19() != 0 && this._targetPc.getMr() >= l1skills.gettype19())
          probability -= 15; 
        if (l1skills.gettype20() != 0 && attackLevel - defenseLevel > l1skills.gettype20())
          probability = 70; 
        if (l1skills.gettype21() != 0 && probability >= l1skills.gettype21())
          probability = l1skills.gettype21(); 
        if (this._calcType == 1 && l1skills.gettype22() != 0 && this._targetPc.getMr() >= l1skills.gettype22())
          probability = 5; 
        if (this._calcType == 1 && l1skills.gettype24() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype24()) / 7; 
        if (this._calcType == 1 && l1skills.gettype25() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype25()) / 9; 
        if (this._calcType == 1 && l1skills.gettype26() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype26()) / 13; 
        if (this._calcType == 1 && l1skills.gettype27() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype27()) / 15; 
        if (this._calcType == 1 && l1skills.gettype28() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype28()) / 20; 
        break;
      case 174:
        if (attackLevel > defenseLevel) {
          probability = ConfigElfSkill.STRIKER_GALE_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigElfSkill.STRIKER_GALE_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigElfSkill.STRIKER_GALE_3;
        } 
        if (ConfigElfSkill.STRIKER_GALE_INT > 0.0D)
          probability = (int)(probability + ConfigElfSkill.STRIKER_GALE_INT * this._pc.getInt()); 
        if (ConfigElfSkill.STRIKER_GALE_MR > 0.0D)
          probability = (int)(probability - ConfigElfSkill.STRIKER_GALE_MR * defenseMr); 
        break;
      case 173:
        if (attackLevel > defenseLevel) {
          probability = ConfigElfSkill.POLLUTE_WATER_RND_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigElfSkill.POLLUTE_WATER_RND_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigElfSkill.POLLUTE_WATER_RND_3;
        } 
        if (ConfigElfSkill.POLLUTE_WATER_INT > 0.0D)
          probability = (int)(probability + ConfigElfSkill.POLLUTE_WATER_INT * this._pc.getInt()); 
        if (ConfigElfSkill.POLLUTE_WATER_MR > 0.0D)
          probability = (int)(probability - ConfigElfSkill.POLLUTE_WATER_MR * defenseMr); 
        break;
      case 157:
        if (attackLevel > defenseLevel) {
          probability = ConfigElfSkill.EARTH_BIND_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigElfSkill.EARTH_BIND_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigElfSkill.EARTH_BIND_3;
        } 
        if (ConfigElfSkill.EARTH_BIND_INT > 0.0D)
          probability = (int)(probability + ConfigElfSkill.EARTH_BIND_INT * this._pc.getInt()); 
        if (ConfigElfSkill.EARTH_BIND_MR > 0.0D)
          probability = (int)(probability - ConfigElfSkill.EARTH_BIND_MR * defenseMr); 
        break;
      case 153:
        if (attackLevel > defenseLevel) {
          probability = ConfigElfSkill.ERASE_MAGIC_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigElfSkill.ERASE_MAGIC_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigElfSkill.ERASE_MAGIC_3;
        } 
        if (ConfigElfSkill.ERASE_MAGIC_INT > 0.0D)
          probability = (int)(probability + ConfigElfSkill.ERASE_MAGIC_INT * this._pc.getInt()); 
        if (ConfigElfSkill.ERASE_MAGIC_MR > 0.0D)
          probability = (int)(probability - ConfigElfSkill.ERASE_MAGIC_MR * defenseMr); 
        break;
      case 161:
        if (attackLevel > defenseLevel) {
          probability = ConfigElfSkill.AREA_OF_SILENCE_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigElfSkill.AREA_OF_SILENCE_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigElfSkill.AREA_OF_SILENCE_3;
        } 
        if (ConfigElfSkill.AREA_OF_SILENCE_INT > 0.0D)
          probability = (int)(probability + ConfigElfSkill.AREA_OF_SILENCE_INT * this._pc.getInt()); 
        if (ConfigElfSkill.AREA_OF_SILENCE_MR > 0.0D)
          probability = (int)(probability - ConfigElfSkill.AREA_OF_SILENCE_MR * defenseMr); 
        break;
      case 152:
        if (attackLevel > defenseLevel) {
          probability = ConfigElfSkill.ENTANGLE_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigElfSkill.ENTANGLE_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigElfSkill.ENTANGLE_3;
        } 
        if (ConfigElfSkill.ENTANGLE_INT > 0.0D)
          probability = (int)(probability + ConfigElfSkill.ENTANGLE_INT * this._pc.getInt()); 
        if (ConfigElfSkill.ENTANGLE_MR > 0.0D)
          probability = (int)(probability - ConfigElfSkill.ENTANGLE_MR * defenseMr); 
        break;
      case 167:
        if (attackLevel > defenseLevel) {
          probability = ConfigElfSkill.WIND_SHACKLE_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigElfSkill.WIND_SHACKLE_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigElfSkill.WIND_SHACKLE_3;
        } 
        if (ConfigElfSkill.WIND_SHACKLE_INT > 0.0D)
          probability = (int)(probability + ConfigElfSkill.WIND_SHACKLE_INT * this._pc.getInt()); 
        if (ConfigElfSkill.WIND_SHACKLE_MR > 0.0D)
          probability = (int)(probability - ConfigElfSkill.WIND_SHACKLE_MR * defenseMr); 
        break;
      case 133:
      case 145:
        if (l1skills.gettype1() != 0 && attackLevel > defenseLevel)
          probability = l1skills.gettype1(); 
        if (l1skills.gettype2() != 0 && attackLevel == defenseLevel)
          probability = l1skills.gettype2(); 
        if (l1skills.gettype3() != 0 && attackLevel < defenseLevel)
          probability = l1skills.gettype3(); 
        if (l1skills.gettype4() != 0)
          probability += l1skills.gettype4(); 
        if (l1skills.gettype5() != 0)
          probability += l1skills.gettype5() * (attackLevel - defenseLevel) / 10; 
        if (l1skills.gettype6() != 0)
          probability += l1skills.gettype6() * this._pc.getInt() / 10; 
        if (l1skills.gettype7() != 0)
          probability += l1skills.gettype7() + (attackLevel - defenseLevel) * 5; 
        if (l1skills.gettype8() != 0)
          probability += l1skills.gettype8() + (attackLevel - defenseLevel) * 2; 
        if (l1skills.gettype9() != 0)
          probability += l1skills.gettype9() + attackLevel - defenseLevel; 
        if (l1skills.gettype10() != 0 && this._pc.getInt() >= l1skills.gettype10())
          probability += 3; 
        if (l1skills.gettype11() != 0)
          probability += l1skills.gettype11() * (attackLevel - defenseLevel); 
        if (l1skills.gettype12() != 0)
          probability = (int)(probability + 
            l1skills.gettype12() + (this._pc.getMr() - l1skills.gettype12()) * 0.02D); 
        if (l1skills.gettype13() != 0)
          probability = (int)(probability + 
            l1skills.gettype13() + (this._pc.getMr() - l1skills.gettype13()) * 0.04D); 
        if (this._calcType == 1 && l1skills.gettype14() != 0 && this._targetPc.getMr() >= l1skills.gettype14())
          probability -= l1skills.gettype14() / 7; 
        if (this._calcType == 1 && l1skills.gettype15() != 0 && this._targetPc.getMr() >= l1skills.gettype15())
          probability -= l1skills.gettype15() / 9; 
        if (this._calcType == 1 && l1skills.gettype16() != 0 && this._targetPc.getMr() >= l1skills.gettype16())
          probability -= l1skills.gettype16() / 13; 
        if (this._calcType == 1 && l1skills.gettype17() != 0 && this._targetPc.getMr() >= l1skills.gettype17())
          probability -= l1skills.gettype17() / 15; 
        if (this._calcType == 1 && l1skills.gettype18() != 0 && this._targetPc.getMr() >= l1skills.gettype18())
          probability -= l1skills.gettype18() / 20; 
        if (this._calcType == 1 && l1skills.gettype19() != 0 && this._targetPc.getMr() >= l1skills.gettype19())
          probability -= 15; 
        if (l1skills.gettype20() != 0 && attackLevel - defenseLevel > l1skills.gettype20())
          probability = 70; 
        if (l1skills.gettype21() != 0 && probability >= l1skills.gettype21())
          probability = l1skills.gettype21(); 
        if (this._calcType == 1 && l1skills.gettype22() != 0 && this._targetPc.getMr() >= l1skills.gettype22())
          probability = 5; 
        if (this._calcType == 1 && l1skills.gettype24() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype24()) / 7; 
        if (this._calcType == 1 && l1skills.gettype25() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype25()) / 9; 
        if (this._calcType == 1 && l1skills.gettype26() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype26()) / 13; 
        if (this._calcType == 1 && l1skills.gettype27() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype27()) / 15; 
        if (this._calcType == 1 && l1skills.gettype28() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype28()) / 20; 
        break;
      case 64:
        if (attackLevel > defenseLevel) {
          probability = ConfigWizardSkill.SILENCE_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigWizardSkill.SILENCE_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigWizardSkill.SILENCE_3;
        } 
        if (ConfigWizardSkill.SILENCE_INT > 0.0D)
          probability = (int)(probability + ConfigWizardSkill.SILENCE_INT * this._pc.getInt()); 
        if (ConfigWizardSkill.SILENCE_MR > 0.0D)
          probability = (int)(probability - ConfigWizardSkill.SILENCE_MR * defenseMr); 
        break;
      case 33:
        if (attackLevel > defenseLevel) {
          probability = ConfigWizardSkill.CURSE_PARALYZE_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigWizardSkill.CURSE_PARALYZE_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigWizardSkill.CURSE_PARALYZE_3;
        } 
        if (ConfigWizardSkill.CURSE_PARALYZE_INT > 0.0D)
          probability = (int)(probability + ConfigWizardSkill.CURSE_PARALYZE_INT * this._pc.getInt()); 
        if (ConfigWizardSkill.CURSE_PARALYZE_MR > 0.0D)
          probability = (int)(probability - ConfigWizardSkill.CURSE_PARALYZE_MR * defenseMr); 
        break;
      case 44:
        if (attackLevel > defenseLevel) {
          probability = ConfigWizardSkill.CANCELLATION_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigWizardSkill.CANCELLATION_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigWizardSkill.CANCELLATION_3;
        } 
        if (ConfigWizardSkill.CANCELLATION_INT > 0.0D)
          probability = (int)(probability + ConfigWizardSkill.CANCELLATION_INT * this._pc.getInt()); 
        if (ConfigWizardSkill.CANCELLATION_MR > 0.0D)
          probability = (int)(probability - ConfigWizardSkill.CANCELLATION_MR * defenseMr); 
        break;
      case 50:
        if (attackLevel > defenseLevel) {
          probability = ConfigWizardSkill.ICE_LANCE_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigWizardSkill.ICE_LANCE_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigWizardSkill.ICE_LANCE_3;
        } 
        if (ConfigWizardSkill.ICE_LANCE_INT > 0.0D)
          probability = (int)(probability + ConfigWizardSkill.ICE_LANCE_INT * this._pc.getInt()); 
        if (ConfigWizardSkill.ICE_LANCE_MR > 0.0D)
          probability = (int)(probability - ConfigWizardSkill.ICE_LANCE_MR * defenseMr); 
        break;
      case 71:
        if (attackLevel > defenseLevel) {
          probability = ConfigWizardSkill.DECAY_POTION_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigWizardSkill.DECAY_POTION_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigWizardSkill.DECAY_POTION_3;
        } 
        if (ConfigWizardSkill.DECAY_POTION_INT > 0.0D)
          probability = (int)(probability + ConfigWizardSkill.DECAY_POTION_INT * this._pc.getInt()); 
        if (ConfigWizardSkill.DECAY_POTION_MR > 0.0D)
          probability = (int)(probability - ConfigWizardSkill.DECAY_POTION_MR * defenseMr); 
        break;
      case 66:
        if (attackLevel > defenseLevel) {
          probability = ConfigWizardSkill.FOG_OF_SLEEPING_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigWizardSkill.FOG_OF_SLEEPING_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigWizardSkill.FOG_OF_SLEEPING_3;
        } 
        if (ConfigWizardSkill.FOG_OF_SLEEPING_INT > 0.0D)
          probability = (int)(probability + ConfigWizardSkill.FOG_OF_SLEEPING_INT * this._pc.getInt()); 
        if (ConfigWizardSkill.FOG_OF_SLEEPING_MR > 0.0D)
          probability = (int)(probability - ConfigWizardSkill.FOG_OF_SLEEPING_MR * defenseMr); 
        break;
      case 40:
        if (attackLevel > defenseLevel) {
          probability = ConfigWizardSkill.DARKNESS_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigWizardSkill.DARKNESS_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigWizardSkill.DARKNESS_3;
        } 
        if (ConfigWizardSkill.DARKNESS_INT > 0.0D)
          probability = (int)(probability + ConfigWizardSkill.DARKNESS_INT * this._pc.getInt()); 
        if (ConfigWizardSkill.DARKNESS_MR > 0.0D)
          probability = (int)(probability - ConfigWizardSkill.DARKNESS_MR * defenseMr); 
        break;
      case 27:
      case 29:
      case 39:
        probability = (int)(l1skills.getProbabilityDice() / 10.0D * (attackLevel - defenseLevel));
        if (this._pc.isGm()) {
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("type1;" + probability));
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("1公式;(dice/10)*(我等-对等)级"));
        } 
        probability += l1skills.getProbabilityValue();
        if (this._pc.isGm()) {
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("type2;" + probability));
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("2公式:+SKILLS栏位ProbabilityValue"));
        } 
        if (l1skills.gettype23() != 0 && this._pc.getOriginalMagicHit() > 0)
          this._pc.addOriginalMagicHit(this._pc.getOriginalMagicHit() * l1skills.gettype23() / 100); 
        probability += this._pc.getOriginalMagicHit();
        if (this._pc.isGm()) {
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("type3;" + probability));
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("3公式:自身魔法命中增加成功机率"));
        } 
        probability += magichit.intValue();
        if (this._pc.isGm()) {
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("type4;" + probability));
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("4公式:智力魔法命中补正"));
        } 
        if (l1skills.gettype1() != 0 && attackLevel > defenseLevel)
          probability = l1skills.gettype1(); 
        if (l1skills.gettype2() != 0 && attackLevel == defenseLevel)
          probability = l1skills.gettype2(); 
        if (l1skills.gettype3() != 0 && attackLevel < defenseLevel)
          probability = l1skills.gettype3(); 
        if (l1skills.gettype4() != 0)
          probability += l1skills.gettype4(); 
        if (l1skills.gettype5() != 0)
          probability += l1skills.gettype5() * (attackLevel - defenseLevel) / 10; 
        if (l1skills.gettype6() != 0)
          probability += l1skills.gettype6() * this._pc.getInt() / 10; 
        if (l1skills.gettype7() != 0)
          probability += l1skills.gettype7() + (attackLevel - defenseLevel) * 5; 
        if (l1skills.gettype8() != 0)
          probability += l1skills.gettype8() + (attackLevel - defenseLevel) * 2; 
        if (l1skills.gettype9() != 0)
          probability += l1skills.gettype9() + attackLevel - defenseLevel; 
        if (l1skills.gettype10() != 0 && this._pc.getInt() >= l1skills.gettype10())
          probability += 3; 
        if (l1skills.gettype11() != 0)
          probability += l1skills.gettype11() * (attackLevel - defenseLevel); 
        if (l1skills.gettype12() != 0)
          probability = (int)(probability + 
            l1skills.gettype12() + (this._pc.getMr() - l1skills.gettype12()) * 0.02D); 
        if (l1skills.gettype13() != 0)
          probability = (int)(probability + 
            l1skills.gettype13() + (this._pc.getMr() - l1skills.gettype13()) * 0.04D); 
        if (this._calcType == 1 && l1skills.gettype14() != 0 && this._targetPc.getMr() >= l1skills.gettype14())
          probability -= l1skills.gettype14() / 7; 
        if (this._calcType == 1 && l1skills.gettype15() != 0 && this._targetPc.getMr() >= l1skills.gettype15())
          probability -= l1skills.gettype15() / 9; 
        if (this._calcType == 1 && l1skills.gettype16() != 0 && this._targetPc.getMr() >= l1skills.gettype16())
          probability -= l1skills.gettype16() / 13; 
        if (this._calcType == 1 && l1skills.gettype17() != 0 && this._targetPc.getMr() >= l1skills.gettype17())
          probability -= l1skills.gettype17() / 15; 
        if (this._calcType == 1 && l1skills.gettype18() != 0 && this._targetPc.getMr() >= l1skills.gettype18())
          probability -= l1skills.gettype18() / 20; 
        if (this._calcType == 1 && l1skills.gettype19() != 0 && this._targetPc.getMr() >= l1skills.gettype19())
          probability -= 15; 
        if (l1skills.gettype20() != 0 && attackLevel - defenseLevel > l1skills.gettype20())
          probability = 70; 
        if (l1skills.gettype21() != 0 && probability >= l1skills.gettype21())
          probability = l1skills.gettype21(); 
        if (this._calcType == 1 && l1skills.gettype22() != 0 && this._targetPc.getMr() >= l1skills.gettype22())
          probability = 5; 
        if (this._calcType == 1 && l1skills.gettype24() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype24()) / 7; 
        if (this._calcType == 1 && l1skills.gettype25() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype25()) / 9; 
        if (this._calcType == 1 && l1skills.gettype26() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype26()) / 13; 
        if (this._calcType == 1 && l1skills.gettype27() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype27()) / 15; 
        if (this._calcType == 1 && l1skills.gettype28() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype28()) / 20; 
        probability -= getTargetMr() / 10;
        if (this._pc.isGm())
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage("type5:最终值对方抗/10=" + probability)); 
        if (l1skills.gettype22() != 0 && this._targetPc.getMr() >= l1skills.gettype22())
          probability = 5; 
        break;
      case 87:
        attackLevel += this._pc.getStunLevel();
        if (this._targetPc.hasSkillEffect(87) && ConfigOther.SHOCK_STUN_OVERLAY == 0) {
          L1SpawnUtil.spawnEffect(81162, 3, this._targetPc.getX(), this._targetPc.getY(), this._targetPc.getMapId(), (L1Character)this._targetPc, 0);
          break;
        } 
        if (this._pc.isGm()) {
          probability = 100;
          break;
        } 
        if (defenseLevel - attackLevel >= 2) {
          probability = ConfigKnightSkill.IMPACT_HALO_4;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigKnightSkill.IMPACT_HALO_3;
        } 
        if (attackLevel > defenseLevel) {
          probability = ConfigKnightSkill.IMPACT_HALO_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigKnightSkill.IMPACT_HALO_2;
        } 
        if (ConfigKnightSkill.IMPACT_HALO_INT > 0.0D)
          probability = (int)(probability + ConfigKnightSkill.IMPACT_HALO_INT * this._pc.getInt()); 
        if (ConfigKnightSkill.IMPACT_HALO_MR > 0.0D)
          probability = (int)(probability - ConfigKnightSkill.IMPACT_HALO_MR * defenseMr); 
        probability += this._pc.getOriginalMagicHit();
        probability += this._pc.getaddStunLevel();
        break;
      case 103:
        if (attackLevel > defenseLevel) {
          probability = ConfigDarkElfSkill.DARK_BLIND_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigDarkElfSkill.DARK_BLIND_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigDarkElfSkill.DARK_BLIND_3;
        } 
        if (ConfigDarkElfSkill.DARK_BLIND_INT > 0.0D)
          probability = (int)(probability + ConfigDarkElfSkill.DARK_BLIND_INT * this._pc.getInt()); 
        if (ConfigDarkElfSkill.DARK_BLIND_MR > 0.0D)
          probability = (int)(probability - ConfigDarkElfSkill.DARK_BLIND_MR * defenseMr); 
        break;
      case 112:
        if (attackLevel > defenseLevel) {
          probability = ConfigDarkElfSkill.ARMOR_BREAK_CHANCE_1;
          break;
        } 
        if (attackLevel == defenseLevel) {
          probability = ConfigDarkElfSkill.ARMOR_BREAK_CHANCE_2;
          break;
        } 
        if (attackLevel < defenseLevel)
          probability = ConfigDarkElfSkill.ARMOR_BREAK_CHANCE_3; 
        break;
      case 212:
        if (attackLevel > defenseLevel) {
          probability = ConfigIllusionstSkill.PHAN_TASM_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigIllusionstSkill.PHAN_TASM_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigIllusionstSkill.PHAN_TASM_3;
        } 
        if (ConfigIllusionstSkill.PHANTASM_INT > 0.0D)
          probability = (int)(probability + ConfigIllusionstSkill.PHANTASM_INT * this._pc.getInt()); 
        if (ConfigIllusionstSkill.PHANTASM_MR > 0.0D)
          probability = (int)(probability - ConfigIllusionstSkill.PHANTASM_MR * defenseMr); 
        break;
      case 202:
      case 217:
        probability = Random.nextInt(11) + 20;
        probability += (attackLevel - defenseLevel) * 2;
        probability += this._pc.getOriginalMagicHit();
        probability += magichit.intValue();
        if (this._pc.isIllusionist() && this._pc.getlogpcpower_SkillFor1() != 0)
          probability += this._pc.getlogpcpower_SkillFor1(); 
        probability += (int)(l1skills.getProbabilityDice() / 10.0D * (attackLevel - defenseLevel));
        if (l1skills.gettype1() != 0 && attackLevel > defenseLevel)
          probability = l1skills.gettype1(); 
        if (l1skills.gettype2() != 0 && attackLevel == defenseLevel)
          probability = l1skills.gettype2(); 
        if (l1skills.gettype3() != 0 && attackLevel < defenseLevel)
          probability = l1skills.gettype3(); 
        if (l1skills.gettype4() != 0)
          probability += l1skills.gettype4(); 
        if (l1skills.gettype5() != 0)
          probability += l1skills.gettype5() * (attackLevel - defenseLevel) / 10; 
        if (l1skills.gettype6() != 0)
          probability += l1skills.gettype6() * this._pc.getInt() / 10; 
        if (l1skills.gettype7() != 0)
          probability += l1skills.gettype7() + (attackLevel - defenseLevel) * 5; 
        if (l1skills.gettype8() != 0)
          probability += l1skills.gettype8() + (attackLevel - defenseLevel) * 2; 
        if (l1skills.gettype9() != 0)
          probability += l1skills.gettype9() + attackLevel - defenseLevel; 
        if (l1skills.gettype10() != 0 && this._pc.getInt() >= l1skills.gettype10())
          probability += 3; 
        if (l1skills.gettype11() != 0)
          probability += l1skills.gettype11() * (attackLevel - defenseLevel); 
        if (l1skills.gettype12() != 0)
          probability = (int)(probability + 
            l1skills.gettype12() + (this._pc.getMr() - l1skills.gettype12()) * 0.02D); 
        if (l1skills.gettype13() != 0)
          probability = (int)(probability + 
            l1skills.gettype13() + (this._pc.getMr() - l1skills.gettype13()) * 0.04D); 
        if (this._calcType == 1 && l1skills.gettype14() != 0 && this._targetPc.getMr() >= l1skills.gettype14())
          probability -= l1skills.gettype14() / 7; 
        if (this._calcType == 1 && l1skills.gettype15() != 0 && this._targetPc.getMr() >= l1skills.gettype15())
          probability -= l1skills.gettype15() / 9; 
        if (this._calcType == 1 && l1skills.gettype16() != 0 && this._targetPc.getMr() >= l1skills.gettype16())
          probability -= l1skills.gettype16() / 13; 
        if (this._calcType == 1 && l1skills.gettype17() != 0 && this._targetPc.getMr() >= l1skills.gettype17())
          probability -= l1skills.gettype17() / 15; 
        if (this._calcType == 1 && l1skills.gettype18() != 0 && this._targetPc.getMr() >= l1skills.gettype18())
          probability -= l1skills.gettype18() / 20; 
        if (this._calcType == 1 && l1skills.gettype19() != 0 && this._targetPc.getMr() >= l1skills.gettype19())
          probability -= 15; 
        if (l1skills.gettype20() != 0 && attackLevel - defenseLevel > l1skills.gettype20())
          probability = 70; 
        if (l1skills.gettype21() != 0 && probability >= l1skills.gettype21())
          probability = l1skills.gettype21(); 
        if (this._calcType == 1 && l1skills.gettype22() != 0 && this._targetPc.getMr() >= l1skills.gettype22())
          probability = 5; 
        if (this._calcType == 1 && l1skills.gettype24() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype24()) / 7; 
        if (this._calcType == 1 && l1skills.gettype25() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype25()) / 9; 
        if (this._calcType == 1 && l1skills.gettype26() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype26()) / 13; 
        if (this._calcType == 1 && l1skills.gettype27() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype27()) / 15; 
        if (this._calcType == 1 && l1skills.gettype28() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype28()) / 20; 
        break;
      case 208:
        if (attackLevel > defenseLevel) {
          probability = ConfigIllusionstSkill.BONE_BREAK_1;
        } else if (attackLevel == defenseLevel) {
          probability = ConfigIllusionstSkill.BONE_BREAK_2;
        } else if (attackLevel < defenseLevel) {
          probability = ConfigIllusionstSkill.BONE_BREAK_3;
        } 
        if (ConfigIllusionstSkill.BONE_BREAK_INT > 0.0D)
          probability = (int)(probability + ConfigIllusionstSkill.BONE_BREAK_INT * this._pc.getInt()); 
        if (ConfigIllusionstSkill.BONE_BREAK_MR > 0.0D)
          probability = (int)(probability - ConfigIllusionstSkill.BONE_BREAK_MR * defenseMr); 
        break;
      case 183:
      case 188:
      case 193:
        probability += l1skills.getProbabilityValue();
        probability += this._pc.getOriginalMagicHit();
        probability += (int)(l1skills.getProbabilityDice() / 10.0D * (attackLevel - defenseLevel));
        break;
      case 67:
        probability = 3 * (attackLevel - defenseLevel) + 225 - getTargetMr();
        probability += (int)(l1skills.getProbabilityDice() / 10.0D * (attackLevel - defenseLevel));
        break;
      default:
        dice2 = l1skills.getProbabilityDice();
        diceCount2 = 0;
        diceCount2 = getMagicBonus() + getMagicLevel();
        diceCount2 = Math.max(diceCount2, 1);
        i = 0;
        while (i < diceCount2) {
          if (dice2 > 0)
            probability += L1MagicMode._random.nextInt(dice2) + 1; 
          i++;
        } 
        probability += this._pc.getOriginalMagicHit();
        probability += magichit.intValue();
        probability -= getTargetMr() / 10;
        if (l1skills.gettype1() != 0 && attackLevel > defenseLevel)
          probability = l1skills.gettype1(); 
        if (l1skills.gettype2() != 0 && attackLevel == defenseLevel)
          probability = l1skills.gettype2(); 
        if (l1skills.gettype3() != 0 && attackLevel < defenseLevel)
          probability = l1skills.gettype3(); 
        if (l1skills.gettype4() != 0)
          probability += l1skills.gettype4(); 
        if (l1skills.gettype5() != 0)
          probability += l1skills.gettype5() * (attackLevel - defenseLevel) / 10; 
        if (l1skills.gettype6() != 0)
          probability += l1skills.gettype6() * this._pc.getInt() / 10; 
        if (l1skills.gettype7() != 0)
          probability += l1skills.gettype7() + (attackLevel - defenseLevel) * 5; 
        if (l1skills.gettype8() != 0)
          probability += l1skills.gettype8() + (attackLevel - defenseLevel) * 2; 
        if (l1skills.gettype9() != 0)
          probability += l1skills.gettype9() + attackLevel - defenseLevel; 
        if (l1skills.gettype10() != 0 && this._pc.getInt() >= l1skills.gettype10())
          probability += 3; 
        if (l1skills.gettype11() != 0)
          probability += l1skills.gettype11() * (attackLevel - defenseLevel); 
        if (l1skills.gettype12() != 0)
          probability = (int)(probability + 
            l1skills.gettype12() + (this._pc.getMr() - l1skills.gettype12()) * 0.02D); 
        if (l1skills.gettype13() != 0)
          probability = (int)(probability + 
            l1skills.gettype13() + (this._pc.getMr() - l1skills.gettype13()) * 0.04D); 
        if (this._calcType == 1 && l1skills.gettype14() != 0 && this._targetPc.getMr() >= l1skills.gettype14())
          probability -= l1skills.gettype14() / 7; 
        if (this._calcType == 1 && l1skills.gettype15() != 0 && this._targetPc.getMr() >= l1skills.gettype15())
          probability -= l1skills.gettype15() / 9; 
        if (this._calcType == 1 && l1skills.gettype16() != 0 && this._targetPc.getMr() >= l1skills.gettype16())
          probability -= l1skills.gettype16() / 13; 
        if (this._calcType == 1 && l1skills.gettype17() != 0 && this._targetPc.getMr() >= l1skills.gettype17())
          probability -= l1skills.gettype17() / 15; 
        if (this._calcType == 1 && l1skills.gettype18() != 0 && this._targetPc.getMr() >= l1skills.gettype18())
          probability -= l1skills.gettype18() / 20; 
        if (this._calcType == 1 && l1skills.gettype19() != 0 && this._targetPc.getMr() >= l1skills.gettype19())
          probability -= 15; 
        if (l1skills.gettype20() != 0 && attackLevel - defenseLevel > l1skills.gettype20())
          probability = 70; 
        if (l1skills.gettype21() != 0 && probability >= l1skills.gettype21())
          probability = l1skills.gettype21(); 
        if (this._calcType == 1 && l1skills.gettype22() != 0 && this._targetPc.getMr() >= l1skills.gettype22())
          probability = 5; 
        if (this._calcType == 1 && l1skills.gettype24() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype24()) / 7; 
        if (this._calcType == 1 && l1skills.gettype25() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype25()) / 9; 
        if (this._calcType == 1 && l1skills.gettype26() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype26()) / 13; 
        if (this._calcType == 1 && l1skills.gettype27() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype27()) / 15; 
        if (this._calcType == 1 && l1skills.gettype28() != 0)
          probability -= (this._targetPc.getMr() - l1skills.gettype28()) / 20; 
        if (skillId == 36) {
          double probabilityRevision = 1.0D;
          if (this._targetNpc.getMaxHp() * 1 / 4 > this._targetNpc.getCurrentHp()) {
            probabilityRevision = 1.3D;
          } else if (this._targetNpc.getMaxHp() * 2 / 4 > this._targetNpc.getCurrentHp()) {
            probabilityRevision = 1.2D;
          } else if (this._targetNpc.getMaxHp() * 3 / 4 > this._targetNpc.getCurrentHp()) {
            probabilityRevision = 1.1D;
          } 
          probability = (int)(probability * probabilityRevision);
        } 
        break;
    } 
    switch (this._calcType) {
      case 1:
        switch (skillId) {
          case 157:
          case 192:
            probability -= this._targetPc.getRegistSustain();
            break;
          case 87:
            probability -= this._targetPc.getRegistStun();
            break;
          case 33:
            probability -= this._targetPc.getRegistStone();
            break;
          case 66:
          case 103:
          case 212:
            probability -= this._targetPc.getRegistSleep();
            break;
          case 50:
          case 80:
            probability -= this._targetPc.getRegistFreeze();
            break;
          case 20:
          case 40:
            probability -= this._targetPc.getRegistBlind();
            break;
        } 
        break;
    } 
    return probability;
  }
  
  public int calcMagicDamage(int skillId) {
    int damage = 0;
    switch (this._calcType) {
      case 1:
        damage = calcPcMagicDamage(skillId);
        break;
      case 2:
        damage = calcNpcMagicDamage(skillId);
        break;
    } 
    L1Skills l1skills = SkillsTable.get().getTemplate(skillId);
    if (l1skills.getTarget().equals("attack") && l1skills.getArea() == 0) {
      AttrAmuletEffect();
      MoonAmuletEffect();
      Imperius_Tshirt_Effect();
    } 
    damage = calcMrDefense(damage);
    return damage;
  }
  
  private int calcPcMagicDamage(int skillId) {
    if (this._targetPc == null)
      return 0; 
    if (this._targetPc == this._pc)
      return 0; 
    if (L1MagicMode.dmg0((L1Character)this._targetPc))
      return 0; 
    if (calcEvasion())
      return 0; 
    if (this._targetPc.getnewcharpra())
      return 0; 
    if (this._pc.getnewcharpra())
      return 0; 
    int dmg = 0;
    if (skillId == 108) {
      dmg = this._pc.getCurrentMp();
    } else {
      dmg = calcMagicDiceDamage(skillId);
      dmg = (int)(dmg * getLeverage() / 10.0D);
    } 
    if (this._pc.get_other().get_Ran_PvP_magic_b() > 0 && 
      L1MagicMode._random.nextInt(100) + 1 <= this._pc.get_other().get_Ran_PvP_magic_b())
      if (this._pc.get_other().getPvP_magic_b() >= 1.0D) {
        dmg = (int)(dmg * this._pc.get_other().getPvP_magic_b());
      } else {
        dmg = (int)(dmg * (1.0D + this._pc.get_other().getPvP_magic_b()));
      }  
    if (this._targetPc.get_other().get_PvP_magic_r() > 0)
      dmg -= this._targetPc.get_other().get_PvP_magic_r(); 
    if (this._targetPc.isActived() && this._targetPc.IsAttackTeleport() && !this._targetPc.hasSkillEffect(6955)) {
      this._targetPc.setSkillEffect(6599, 3000);
      this._targetPc.sendPackets((ServerBasePacket)new S_SystemMessage("您受到攻击3秒后自动瞬移"));
    } 
    dmg -= this._targetPc.getMagicDmgReduction() + this._targetPc.get_magic_reduction_dmg();
    dmg -= this._targetPc.dmgDowe();
    if (this._targetPc.getClanid() != 0)
      dmg = (int)(dmg - L1MagicMode.getDamageReductionByClan(this._targetPc)); 
    if (this._targetPc.hasSkillEffect(88)) {
      int targetPcLvl = Math.max(this._targetPc.getLevel(), 50);
      dmg -= (targetPcLvl - 50) / 5 + 1;
    } 
    if (this._pc.isCrown()) {
      dmg = (int)(dmg * Config_Pc_Damage.Crown_ADD_MagicPC);
    } else if (this._pc.isKnight()) {
      dmg = (int)(dmg * Config_Pc_Damage.Knight_ADD_MagicPC);
    } else if (this._pc.isElf()) {
      dmg = (int)(dmg * Config_Pc_Damage.Elf_ADD_MagicPC);
    } else if (this._pc.isDarkelf()) {
      dmg = (int)(dmg * Config_Pc_Damage.Darkelf_ADD_MagicPC);
    } else if (this._pc.isWizard()) {
      dmg = (int)(dmg * Config_Pc_Damage.Wizard_ADD_MagicPC);
    } else if (this._pc.isDragonKnight()) {
      dmg = (int)(dmg * Config_Pc_Damage.DragonKnight_ADD_MagicPC);
    } else if (this._pc.isIllusionist()) {
      dmg = (int)(dmg * Config_Pc_Damage.Illusionist_ADD_MagicPC);
    } 
    int ran = L1MagicMode._random.nextInt(100) + 1;
    if (this._targetPc.getInventory().checkSkillType(133) && ran <= ConfigOther.armor_type21)
      dmg = (int)(dmg * 0.99D); 
    if (this._targetPc.getInventory().checkSkillType(134) && ran <= ConfigOther.armor_type22)
      dmg = (int)(dmg * 0.95D); 
    if (this._targetPc.getInventory().checkSkillType(135) && ran <= ConfigOther.armor_type23)
      dmg = (int)(dmg * 0.9D); 
    if (this._targetPc.getInventory().checkSkillType(136) && ran <= ConfigOther.armor_type24)
      dmg = (int)(dmg * 0.85D); 
    if (this._targetPc.getInventory().checkSkillType(137) && ran <= ConfigOther.armor_type25)
      dmg = (int)(dmg * 0.8D); 
    if (this._pc.isWizard() && this._pc.getlogpcpower_SkillFor1() != 0 && this._pc.getlogpcpower_SkillFor1() >= 1)
      if (RandomArrayList.getInc(100, 1) <= this._pc.getlogpcpower_SkillFor1()) {
        this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._pc.getId(), 5377));
        this._pc.sendPackets((ServerBasePacket)new S_SystemMessage("触发 致命一击"));
        this._pc.setchecklogpc(true);
      } else {
        this._pc.setchecklogpc(false);
      }  
    if (this._pc.isWizard() && this._pc.getEsotericCount() != 0)
      if (this._pc.getEsotericCount() == 4) {
        dmg = (int)(dmg * (1.0D + 0.12D * this._pc.getlogpcpower_SkillFor5()));
      } else if (this._pc.getEsotericCount() == 3) {
        dmg = (int)(dmg * (1.0D + 0.09D * this._pc.getlogpcpower_SkillFor5()));
      } else if (this._pc.getEsotericCount() == 2) {
        dmg = (int)(dmg * (1.0D + 0.06D * this._pc.getlogpcpower_SkillFor5()));
      } else if (this._pc.getEsotericCount() == 1) {
        dmg = (int)(dmg * (1.0D + 0.03D * this._pc.getlogpcpower_SkillFor5()));
      }  
    if (this._targetPc.hasSkillEffect(68))
      dmg = (int)(dmg / ConfigOther.IMMUNE_TO_HARM); 
    if ((this._targetPc.hasSkillEffect(6685) || this._targetPc.hasSkillEffect(6687) || 
      this._targetPc.hasSkillEffect(6688) || this._targetPc.hasSkillEffect(6689)) && 
      L1MagicMode._random.nextInt(100) < 10) {
      dmg /= 2;
      this._targetPc.sendPacketsAll((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), 6320));
    } 
    if (this._targetPc.hasSkillEffect(134) && this._calcType == 1 && 
      this._targetPc.getWis() >= L1MagicMode._random.nextInt(100)) {
      this._pc.sendPacketsAll((ServerBasePacket)new S_DoActionGFX(this._pc.getId(), 2));
      this._pc.receiveDamage((L1Character)this._targetPc, dmg, false, false);
      this._pc.sendPacketsAll((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), 4395));
      dmg = 0;
      this._targetPc.killSkillEffectTimer(134);
    } 
    return Math.max(dmg, 0);
  }
  
  private int calcNpcMagicDamage(int skillId) {
    if (this._targetNpc == null)
      return 0; 
    if (L1MagicMode.dmg0((L1Character)this._targetNpc))
      return 0; 
    int npcId = this._targetNpc.getNpcTemplate().get_npcId();
    Integer tgskill = L1AttackList.SKNPC.get(Integer.valueOf(npcId));
    if (tgskill != null && !this._pc.hasSkillEffect(tgskill.intValue()))
      return 0; 
    Integer tgpoly = L1AttackList.PLNPC.get(Integer.valueOf(npcId));
    if (tgpoly != null && tgpoly.equals(Integer.valueOf(this._pc.getTempCharGfx())))
      return 0; 
    int dmg = 0;
    if (skillId == 108) {
      dmg = this._pc.getCurrentMp();
    } else {
      dmg = calcMagicDiceDamage(skillId);
      dmg = (int)(dmg * getLeverage() / 10.0D);
    } 
    boolean isNowWar = false;
    int castleId = L1CastleLocation.getCastleIdByArea((L1Character)this._targetNpc);
    if (castleId > 0)
      isNowWar = ServerWarExecutor.get().isNowWar(castleId); 
    if (this._pc.isCrown()) {
      dmg = (int)(dmg * Config_Pc_Damage.Crown_ADD_MagicNPC);
    } else if (this._pc.isKnight()) {
      dmg = (int)(dmg * Config_Pc_Damage.Knight_ADD_MagicNPC);
    } else if (this._pc.isElf()) {
      dmg = (int)(dmg * Config_Pc_Damage.Elf_ADD_MagicNPC);
    } else if (this._pc.isDarkelf()) {
      dmg = (int)(dmg * Config_Pc_Damage.Darkelf_ADD_MagicNPC);
    } else if (this._pc.isWizard()) {
      dmg = (int)(dmg * Config_Pc_Damage.Wizard_ADD_MagicNPC);
    } else if (this._pc.isDragonKnight()) {
      dmg = (int)(dmg * Config_Pc_Damage.DragonKnight_ADD_MagicNPC);
    } else if (this._pc.isIllusionist()) {
      dmg = (int)(dmg * Config_Pc_Damage.Illusionist_ADD_MagicNPC);
    } 
    boolean isPet = false;
    if (this._targetNpc instanceof com.lineage.server.model.Instance.L1PetInstance) {
      isPet = true;
      if (this._targetNpc.getMaster().equals(this._pc))
        dmg = 0; 
    } 
    if (this._targetNpc instanceof L1SummonInstance) {
      L1SummonInstance summon = (L1SummonInstance)this._targetNpc;
      if (summon.isExsistMaster())
        isPet = true; 
      if (this._targetNpc.getMaster().equals(this._pc))
        dmg = 0; 
    } 
    if (!isNowWar && isPet && dmg != 0)
      dmg /= 8; 
    if (this._pc.get_followmaster() != null)
      dmg = (int)(dmg * 0.5D); 
    if (!this._targetNpc.getNpcTemplate().is_boss()) {
      L1Npc template = NpcTable.get().getTemplate(this._targetNpc.getNpcId());
      if (template.getImpl().equals("L1Monster") && !this._pc.isActived() && this._pc.get_followmaster() == null && 
        this._pc.hasSkillEffect(6931)) {
        this._pc.killSkillEffectTimer(6931);
        this._pc.setSkillEffect(6932, 1000);
      } 
    } 
    if (this._targetNpc.hasSkillEffect(68))
      dmg /= 2; 
    if (this._targetNpc.hasSkillEffect(134) && this._calcType == 2 && 
      this._targetNpc.getWis() >= L1MagicMode._random.nextInt(100)) {
      this._pc.sendPacketsAll((ServerBasePacket)new S_DoActionGFX(this._pc.getId(), 2));
      this._pc.receiveDamage((L1Character)this._targetNpc, dmg, false, false);
      this._targetNpc.broadcastPacketAll((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), 4395));
      dmg = 0;
      this._targetNpc.killSkillEffectTimer(134);
    } 
    if (this._targetNpc.hasSkillEffect(11059) && this._calcType == 2) {
      this._pc.sendPacketsAll((ServerBasePacket)new S_DoActionGFX(this._pc.getId(), 2));
      this._pc.receiveDamage((L1Character)this._targetNpc, dmg, false, false);
      this._targetNpc.broadcastPacketAll((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), 4395));
      dmg = 0;
    } 
    return dmg;
  }
  
  private void AttrAmuletEffect() {
    int rnd = this._pc.get_AttrAmulet_rnd();
    int dmg = this._pc.get_AttrAmulet_dmg();
    int gfxid = this._pc.get_AttrAmulet_gfxid();
    if (rnd <= 0)
      return; 
    switch (this._calcType) {
      case 1:
        if (L1MagicMode._random.nextInt(1000) < rnd) {
          if (this._targetPc.hasSkillEffect(68))
            dmg /= 2; 
          this._targetPc.sendPacketsAll((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), gfxid));
          this._targetPc.receiveDamage((L1Character)this._pc, dmg, false, true);
        } 
        break;
      case 2:
        if (L1MagicMode._random.nextInt(1000) < rnd) {
          if (this._targetNpc.hasSkillEffect(68))
            dmg /= 2; 
          this._targetNpc.broadcastPacketAll((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), gfxid));
          this._targetNpc.receiveDamage((L1Character)this._pc, dmg);
        } 
        break;
    } 
  }
  
  private int calcMagicDiceDamage(int skillId) {
    L1Skills l1skills = SkillsTable.get().getTemplate(skillId);
    int dice = l1skills.getDamageDice();
    int diceCount = l1skills.getDamageDiceCount();
    int value = l1skills.getDamageValue();
    int magicDamage = 0;
    int charaIntelligence = 0;
    int i = 0;
    while (i < diceCount) {
      magicDamage += L1MagicMode._random.nextInt(dice) + 1;
      i++;
    } 
    magicDamage += value;
    if (this._pc.getClanid() != 0)
      magicDamage = (int)(magicDamage + L1MagicMode.getDamageUpByClan(this._pc)); 
    int spByItem = getTargetSp();
    charaIntelligence = Math.max(this._pc.getInt() + spByItem - 12, 1);
    double attrDeffence = calcAttrResistance(l1skills.getAttr());
    double coefficient = Math.max(1.0D - attrDeffence + charaIntelligence * 3.0D / 32.0D, 0.0D);
    magicDamage = (int)(magicDamage * coefficient);
    magicDamage += this._pc.getOriginalMagicDamage() + this._pc.getMagicDmgModifier();
    return magicDamage;
  }
  
  public int calcHealing(int skillId) {
//    L1Skills l1skills = SkillsTable.get().getTemplate(skillId);
//    int dice = l1skills.getDamageDice();   //8
//    int value = l1skills.getDamageValue();
//    int magicDamage = 0;
//    int magicBonus = getMagicBonus();
//    // DamageValue = 8
//    //magicBonus = 
//    int diceCount = value + magicBonus;
//    int i = 0;
//    while (i < diceCount) {
//      magicDamage += L1MagicMode._random.nextInt(dice) + 1;
//      i++;
//    } 
//    double alignmentRevision = 1.0D;
//    if (getLawful() > 0)
//      alignmentRevision += getLawful() / 32768.0D; 
//    magicDamage = (int)(magicDamage * alignmentRevision);
//    magicDamage = (int)(magicDamage * getLeverage() / 10.0D);
//    if (this._pc.isWizard() || this._pc.isIllusionist()) {
//      magicDamage = (int)(magicDamage * 1.0D);
//    } else if (this._pc.isElf() || this._pc.isDragonKnight()) {
//      magicDamage = (int)(magicDamage * 0.8D);
//    } else if (this._pc.isDarkelf() || this._pc.isCrown()) {
//      magicDamage = (int)(magicDamage * 0.5D);
//    } else if (this._pc.isKnight()) {
//      magicDamage = (int)(magicDamage * 0.3D);
//    } 
//    return magicDamage;
	  
	  
		L1Skills l1skills = SkillsTable.get().getTemplate(skillId);
		int dice = l1skills.getDamageDice();
		int value = l1skills.getDamageValue();
		int magicDamage = 0;

		if (skillId != NATURES_BLESSING) {
			int magicBonus = (getMagicBonus()-2);
			if (magicBonus > 10) {
				magicBonus = 10;
			}

			int diceCount = value + magicBonus;
			for (int i = 0; i < diceCount; i++) {
				magicDamage += (_random.nextInt(dice) + 1);
			}
		} else {
			int Int = 0;
			if (_calcType == PC_PC || _calcType == PC_NPC) {
				Int = _pc.getInt();
			} else if (_calcType == NPC_PC || _calcType == NPC_NPC) {
				Int = _npc.getInt();
			}
			if (Int < 12)
				Int = 12;
			for (int i = 12; i <= Int; i++) {
				if (i == 12)
					magicDamage += (100 + _random.nextInt(80));
				else if (i >= 13 && i <= 17)
					magicDamage += (3 + _random.nextInt(2));
				else if (i >= 18 && i <= 25)
					magicDamage += (10 + _random.nextInt(6));
				else if (i >= 26)
					magicDamage += (1 + _random.nextInt(2));
			}
//			magicDamage /= 2.2;
		}

		double alignmentRevision = 1.0;
		if (getLawful() > 0) {
			alignmentRevision += (getLawful() / 32768.0);
		}

		magicDamage *= alignmentRevision;

	    magicDamage = (int)(magicDamage * alignmentRevision);
	    magicDamage = (int)(magicDamage * getLeverage() / 10.0D);
	    if (this._pc.isWizard() || this._pc.isIllusionist()) {
	      magicDamage = (int)(magicDamage * 1.0D);
	    } else if (this._pc.isElf() || this._pc.isDragonKnight()) {
	      magicDamage = (int)(magicDamage * 0.8D);
	    } else if (this._pc.isDarkelf() || this._pc.isCrown()) {
	      magicDamage = (int)(magicDamage * 0.5D);
	    } else if (this._pc.isKnight()) {
	      magicDamage = (int)(magicDamage * 0.3D);
	    } 

		return magicDamage;
  }
  
  private void Imperius_Tshirt_Effect() {
    int value = 0;
    int rnd = this._pc.get_Imperius_Tshirt_rnd();
    int min = this._pc.get_Tshirt_drainingHP_min();
    int max = this._pc.get_Tshirt_drainingHP_max();
    if (rnd <= 0)
      return; 
    switch (this._calcType) {
      case 1:
        if (L1MagicMode._random.nextInt(1000) < rnd) {
          value = L1MagicMode._random.nextInt(max - min + 1) + min;
          this._targetPc.sendPacketsAll((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), 11769));
          this._targetPc.receiveDamage((L1Character)this._pc, value, false, true);
          short newHp = (short)(this._pc.getCurrentHp() + value);
          this._pc.setCurrentHp(newHp);
        } 
        break;
      case 2:
        if (L1MagicMode._random.nextInt(1000) < rnd) {
          value = L1MagicMode._random.nextInt(max - min + 1) + min;
          this._targetNpc.broadcastPacketAll((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), 11769));
          this._targetNpc.receiveDamage((L1Character)this._pc, value);
          short newHp = (short)(this._pc.getCurrentHp() + value);
          this._pc.setCurrentHp(newHp);
        } 
        break;
    } 
  }
  
  private int calcMrDefense(int dmg) {
    int mr = getTargetMr();
    double mrFloor = 0.0D;
    if (mr < 100) {
      mrFloor = Math.floor(((mr - this._pc.getOriginalMagicHit()) / 2));
    } else if (mr >= 100) {
      mrFloor = Math.floor(((mr - this._pc.getOriginalMagicHit()) / 10));
    } 
    double mrCoefficient = 0.0D;
    if (mr < 100) {
      mrCoefficient = 1.0D - 0.01D * mrFloor;
    } else if (mr >= 100) {
      mrCoefficient = 0.6D - 0.01D * mrFloor;
    } 
    if (!this._pc.getchecklogpc())
      dmg = (int)(dmg * mrCoefficient); 
    this._pc.setchecklogpc(false);
    return dmg;
  }
  
  private void MoonAmuletEffect() {
    int rnd = this._pc.get_MoonAmulet_rnd();
    int dmgmin = this._pc.get_MoonAmulet_dmg_min();
    int dmgmax = this._pc.get_MoonAmulet_dmg_max();
    int gfxid = this._pc.get_MoonAmulet_gfxid();
    if (rnd <= 0)
      return; 
    int damage = 0;
    switch (this._calcType) {
      case 1:
        if (L1MagicMode._random.nextInt(1000) < rnd) {
          damage = L1MagicMode._random.nextInt(dmgmax - dmgmin + 1) + dmgmin;
          if (this._targetPc.hasSkillEffect(68))
            damage /= 2; 
          this._targetPc.sendPacketsAll((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), gfxid));
          this._targetPc.receiveDamage((L1Character)this._pc, damage, false, true);
        } 
        break;
      case 2:
        if (L1MagicMode._random.nextInt(1000) < rnd) {
          damage = L1MagicMode._random.nextInt(dmgmax - dmgmin + 1) + dmgmin;
          if (this._targetNpc.hasSkillEffect(68))
            damage /= 2; 
          this._targetNpc.broadcastPacketAll((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), gfxid));
          this._targetNpc.receiveDamage((L1Character)this._pc, damage);
        } 
        break;
    } 
  }
  
  public void commit(int damage, int drainMana) {
    if (this._calcType == 1 && ConfigGuaji.Guaji_save && this._targetPc.isActived() && 
      this._targetPc.getLevel() <= ConfigGuaji.Guaji_level)
      return; 
    int i = (int)(damage / Math.pow(10.0D, 0.0D) % 10.0D) + ConfigOther.Attack_1;
    int k = (int)(damage / Math.pow(10.0D, 1.0D) % 10.0D) + ConfigOther.Attack_2;
    int h = (int)(damage / Math.pow(10.0D, 2.0D) % 10.0D) + ConfigOther.Attack_3;
    int s = (int)(damage / Math.pow(10.0D, 3.0D) % 10.0D) + ConfigOther.Attack_4;
    int m = (int)(damage / Math.pow(10.0D, 4.0D) % 10.0D) + ConfigOther.Attack_5;
    switch (this._calcType) {
      case 1:
        commitPc(damage, drainMana);
        if (!this._pc.hasSkillEffect(1688))
          break; 
        if (damage > 0 && damage < 10) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), i));
          break;
        } 
        if (damage >= 10 && damage < 100) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), i));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), k));
          break;
        } 
        if (damage >= 100 && damage < 1000) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), i));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), k));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), h));
          break;
        } 
        if (damage >= 1000 && damage < 10000) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), i));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), k));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), h));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), s));
          break;
        } 
        if (damage >= 10000) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), i));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), k));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), h));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), s));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetPc.getId(), m));
        } 
        break;
      case 2:
        commitNpc(damage, drainMana);
        if (!this._pc.hasSkillEffect(1688))
          break; 
        if (damage > 0 && damage < 10) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), i));
          break;
        } 
        if (damage >= 10 && damage < 100) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), i));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), k));
          break;
        } 
        if (damage >= 100 && damage < 1000) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), i));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), k));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), h));
          break;
        } 
        if (damage >= 1000 && damage < 10000) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), i));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), k));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), h));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), s));
          break;
        } 
        if (damage >= 10000) {
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), i));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), k));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), h));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), s));
          this._pc.sendPackets((ServerBasePacket)new S_SkillSound(this._targetNpc.getId(), m));
        } 
        break;
    } 
    if (!ConfigAlt.ALT_ATKMSG)
      return; 
    switch (this._calcType) {
      case 1:
        if (this._pc.getAccessLevel() == 0 && this._targetPc.getAccessLevel() == 0)
          return; 
        break;
      case 2:
        if (this._pc.getAccessLevel() == 0)
          return; 
        break;
    } 
    switch (this._calcType) {
      case 1:
        if (this._pc.getAccessLevel() > 0) {
          StringBuilder atkMsg = new StringBuilder();
          atkMsg.append("对PC送出技能: ");
          atkMsg.append(String.valueOf(String.valueOf(this._pc.getName())) + ">");
          atkMsg.append(String.valueOf(String.valueOf(this._targetPc.getName())) + " ");
          atkMsg.append("伤害: " + damage);
          atkMsg.append(" 目标HP:" + this._targetPc.getCurrentHp());
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, atkMsg.toString()));
        } 
        if (this._targetPc.getAccessLevel() > 0) {
          StringBuilder atkMsg = new StringBuilder();
          atkMsg.append("受到PC技能: ");
          atkMsg.append(String.valueOf(String.valueOf(this._pc.getName())) + ">");
          atkMsg.append(String.valueOf(String.valueOf(this._targetPc.getName())) + " ");
          atkMsg.append("伤害: " + damage);
          atkMsg.append(" 目标HP:" + this._targetPc.getCurrentHp());
          this._targetPc.sendPackets((ServerBasePacket)new S_ServerMessage(166, atkMsg.toString()));
        } 
        break;
      case 2:
        if (this._pc.getAccessLevel() > 0) {
          StringBuilder atkMsg = new StringBuilder();
          atkMsg.append("对NPC送出技能: ");
          atkMsg.append(String.valueOf(String.valueOf(this._pc.getName())) + ">");
          atkMsg.append(String.valueOf(String.valueOf(this._targetNpc.getNameId())) + " ");
          atkMsg.append("伤害: " + damage);
          atkMsg.append(" 目标HP:" + this._targetNpc.getCurrentHp());
          this._pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, atkMsg.toString()));
        } 
        break;
    } 
  }
  
  private void commitPc(int damage, int drainMana) {
    try {
      if (drainMana > 0)
        if (this._targetPc.getCurrentMp() > 0) {
          drainMana = Math.min(drainMana, this._targetPc.getCurrentMp());
          int newMp = this._pc.getCurrentMp() + drainMana;
          this._pc.setCurrentMp(newMp);
        } else {
          drainMana = 0;
        }  
      this._targetPc.receiveManaDamage((L1Character)this._pc, drainMana);
      this._targetPc.receiveDamage((L1Character)this._pc, damage, true, false);
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  private boolean isInWarAreaAndWarTime(L1PcInstance pc, L1PcInstance target) {
    int castleId = L1CastleLocation.getCastleIdByArea((L1Character)pc);
    int targetCastleId = L1CastleLocation.getCastleIdByArea((L1Character)target);
    return (castleId != 0 && targetCastleId != 0 && castleId == targetCastleId && 
      ServerWarExecutor.get().isNowWar(castleId));
  }
  
  private void commitNpc(int damage, int drainMana) {
    try {
      if (drainMana > 0)
        if (this._targetNpc.getCurrentMp() > 0) {
          int drainValue = this._targetNpc.drainMana(drainMana);
          int newMp = this._pc.getCurrentMp() + drainValue;
          this._pc.setCurrentMp(newMp);
        } else {
          drainMana = 0;
        }  
      this._targetNpc.ReceiveManaDamage((L1Character)this._pc, drainMana);
      this._targetNpc.receiveDamage((L1Character)this._pc, damage);
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
